package com.kaifamiao.boxing;

/**
 * 1、将包装了基本数据类型数值的对象中的值自动取出的过程就是自动拆箱(auto-unboxing)
 * 2、自动拆箱只是一种语法糖，实际上在编译阶段还是将相应代码替换成了"手动拆箱"的代码
 */
public class AutoUnboxingTest {

	public static void main(String[] args) {
		
		int primitive = 9527 ;
		
		Integer first = Integer.valueOf( primitive );
		System.out.println( System.identityHashCode( first ) );
		
		Integer second = Integer.valueOf( primitive );
		System.out.println( System.identityHashCode( second ) );
		
		// 用 == 比较 first 和 second 时没有自动拆箱，而是比较两个变量中存储的值
		System.out.println( first == second );
		
		System.out.println( first == primitive ); // auto-unboxing
		// 编译阶段会将 first == primitive 替换为 first.intValue() == primitive
		System.out.println( second == primitive ); // auto-unboxing
		
		int third = first + second ; // auto-unboxing
		System.out.println( third );
		
	}

}
